/*
 * TransactionBO.java
 *
 * Created on February 13, 2007
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package finalintex2web;
import java.util.*;

/**
 * Business object for transactions
 * @author craig marshall
 */
public class TransactionBO {
    
    private String id = null;
    private String date = null;
    private String status = null; 
    private String type = null; 
    private String returntransaction = null; 
    private ArrayList<TransactionLineBO> transactionlines = null;
    private CustomerBO customer = null;
    private StoreBO store = null;
    private EmployeeBO employee = null;
    private PaymentBO payment = null;
    private boolean indb = false , dirty = false;
    private double tax = 0, subtotal = 0, total = 0, taxrate = .06,  change = 0;
   
    
    
    
    /** Creates a new instance of TransactionBO */
    TransactionBO(String id) {
        this.setId(id);
        
    }
    /**Gets the id */
    public String getId() {
        return id;
        
    }

    /**
     * 
     * @param id 
     */
    public void setId(String id) {
        this.id = id;
        this.setDirty(true);
    }

   

    /**
     * 
     * @return 
     */
    public ArrayList<TransactionLineBO> getTransactionlines() {
        return transactionlines;
    }

    /**
     * 
     * @param transactionlines 
     */
    public void setTransactionlines(ArrayList<TransactionLineBO> transactionlines) {
        this.transactionlines = transactionlines;
        this.setDirty(true);
    }

    /**
     * 
     * @return 
     */
    public CustomerBO getCustomer() {
        return customer;
    }

    /**
     * 
     * @param customer 
     */
    public void setCustomer(CustomerBO customer) {
        this.customer = customer;
        this.setDirty(true);
    }

    /**
     * 
     * @return 
     */
    public StoreBO getStore() {
        return store;
    }

    /**
     * 
     * @param store 
     */
    public void setStore(StoreBO store) {
        this.store = store;
        this.setDirty(true);
    }

    /**
     * 
     * @return 
     */
    public EmployeeBO getEmployee() {
        return employee;
    }

    /**
     * 
     * @param employee 
     */
    public void setEmployee(EmployeeBO employee) {
        this.employee = employee;
        this.setDirty(true);
    }

    /**
     * 
     * @return 
     */
    public PaymentBO getPayment() {
        return payment;
    }

    /**
     * 
     * @param payment 
     */
    public void setPayment(PaymentBO payment) {
        this.payment = payment;
        this.setDirty(true);
    }

    /**
     * 
     * @return 
     */
    public boolean isIndb() {
        return indb;
    }

    /**
     * 
     * @param indb 
     */
    public void setIndb(boolean indb) {
        this.indb = indb;
    }

    /**
     * 
     * @return 
     */
    public boolean isDirty() {
        return dirty;
    }

    /**
     * 
     * @param dirty 
     */
    public void setDirty(boolean dirty) {
        this.dirty = dirty;
      
    }

    /**
     * 
     * @return 
     */
    public String getStatus() {
        return status;
    }

    /**
     * 
     * @param status 
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * 
     * @param date 
     */
    public void setDate(String date) {
        this.date = date;
        this.setDirty(true);
    }
    
    /**
     * 
     * @return 
     */
    public String getDate() {
        return date;
    }
     /**
     *  calculates the subtotal
     *  @return double the subtotal
     */
        public double CalcSubtotal(){
        ArrayList<TransactionLineBO> translines = new ArrayList<TransactionLineBO> ();
        translines = this.getTransactionlines();
        for(int x =0; x < translines.size();x++){
             subtotal += translines.get(x).getRevsrc().getPrice();
             if (translines.get(x).getCoup() != null)
                  subtotal -= translines.get(x).getCoup().getAmount();
         }
        return subtotal;
    }
     /**
     *  calculates the tax
     *  @return double the tax
     */
    public double CalcTax(){
        tax = this.subtotal * taxrate;
        return tax;
    }
    
     /**
     *  calculates the total
     *  @return double the total
     */
    public double CalcTotal(){
        total = subtotal + tax;
        return total;
    }
     /**
     *  calculates the change
     *  @return double the change
     */
     public double CalcChange(){
        change = this.getPayment().getAmount() - total;
        return change;
    }

    /**
     * 
     * @return 
     */
    public String getType() {
        return type;
    }

    /**
     * 
     * @param type 
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * 
     * @return 
     */
    public String getReturntransaction() {
        return returntransaction;
    }

    /**
     * 
     * @param returntransaction 
     */
    public void setReturntransaction(String returntransaction) {
        this.returntransaction = returntransaction;
    }
}